﻿using DevExpress.XtraTabbedMdi;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.LookAndFeel;
using Public;
using BUS;

namespace QuanLyKhoHangVatTu
{
    public partial class Main : DevExpress.XtraEditors.XtraForm
    {
        NhomVatTu_BUS nvt_bus = new NhomVatTu_BUS();
        NhomVatTu_PB nvt_pb = new NhomVatTu_PB();
        Kho_BUS k_bus = new Kho_BUS();
        Kho_PB k_pb = new Kho_PB();
        VatTu_BUS vattu_bus = new VatTu_BUS();
        VatTu_PB vattu_pb = new VatTu_PB();
        DonVi_BUS dv_bus = new DonVi_BUS();
        DonVi_PB dv_pb = new DonVi_PB();
        NhanVien_BUS nhanvien_bus = new NhanVien_BUS();
        NhanVien_PB nhanvien_pb = new NhanVien_PB();
        NhomKHNCC_BUS nhom_bus = new NhomKHNCC_BUS();
        NhomKHNCC_PB nhom_pb = new NhomKHNCC_PB();

        public Main()
        {
            InitializeComponent();
        }

        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void navBarControl1_Click(object sender, EventArgs e)
        {

        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietNhomVatTuHangHoa ctnvt = new ChiTietNhomVatTuHangHoa();
            addChild(ctnvt);
        }

        private void Main_Load(object sender, EventArgs e)
        {
            DevExpress.UserSkins.BonusSkins.Register();
            UserLookAndFeel.Default.SetSkinStyle("Office 2007 Blue");

            XtraTabbedMdiManager mdiManager = new XtraTabbedMdiManager();
            mdiManager.MdiParent = this;
        }
        private void addChild(System.Windows.Forms.Form frm)
        {
            foreach (System.Windows.Forms.Form _mdi_child in this.MdiChildren)
            {
                if (_mdi_child.Name == frm.Name)
                    _mdi_child.Close();
            }
            frm.MdiParent = this;
            frm.Show();
        }

        private void barButtonItem32_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Flag_PB.Flag == 1)
            {
                Flag_PB.ThemSua = 1;
                ThemNhomvatTuHangHoa themnvt = new ThemNhomvatTuHangHoa();
                if (themnvt.ShowDialog() == DialogResult.OK)
                {
                    ChiTietNhomVatTuHangHoa ctnvt = new ChiTietNhomVatTuHangHoa();
                    addChild(ctnvt);
                }
            }
            if (Flag_PB.Flag == 2)
            {
                Flag_PB.ThemSua = 1;
                Kho k = new Kho();
                if (k.ShowDialog() == DialogResult.OK)
                {
                    ChiTietKho ctk = new ChiTietKho();
                    addChild(ctk);
                }

            }
            if (Flag_PB.Flag == 3)
            {
                Flag_PB.ThemSua = 1;
                HangHoaVatTu hhvt = new HangHoaVatTu();
                if (hhvt.ShowDialog() == DialogResult.OK)
                {
                    ChiTietVatTuHangHoa ctvthh = new ChiTietVatTuHangHoa();
                    addChild(ctvthh);
                }

            }
            if (Flag_PB.Flag == 4)
            {
                Flag_PB.ThemSua = 1;
                NhanVien nhanvien = new NhanVien();
                if (nhanvien.ShowDialog() == DialogResult.OK)
                {
                    ChiTietNhanVien ctnv = new ChiTietNhanVien();
                    addChild(ctnv);
                }

            }
            if (Flag_PB.Flag == 6)
            {
                Flag_PB.ThemSua = 1;
                DonVi dv = new DonVi();
                if (dv.ShowDialog() == DialogResult.OK)
                {
                    ChiTietDonVi ctdv = new ChiTietDonVi();
                    addChild(ctdv);
                }

            }

            if (Flag_PB.Flag == 8)
            {
                Flag_PB.ThemSua = 1;
                NhomKhachHangNCC nhomkhncc = new NhomKhachHangNCC();
                if (nhomkhncc.ShowDialog() == DialogResult.OK)
                {
                    ChiTietNhomKH_NCC ctnhomkhncc = new ChiTietNhomKH_NCC();
                    addChild(ctnhomkhncc);
                }
            }
        }

        private void barButtonItem33_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Flag_PB.Flag == 1)
            {
                Flag_PB.ThemSua = 2;
                ThemNhomvatTuHangHoa themnvt = new ThemNhomvatTuHangHoa();
                if (themnvt.ShowDialog() == DialogResult.OK)
                {
                    ChiTietNhomVatTuHangHoa ctnvt = new ChiTietNhomVatTuHangHoa();
                    addChild(ctnvt);
                }
            }
            if (Flag_PB.Flag == 2)
            {
                Flag_PB.ThemSua = 2;
                Kho k = new Kho();
                if (k.ShowDialog() == DialogResult.OK)
                {
                    ChiTietKho ctk = new ChiTietKho();
                    addChild(ctk);
                }

            }
            if (Flag_PB.Flag == 3)
            {
                Flag_PB.ThemSua = 2;
                HangHoaVatTu hhvt = new HangHoaVatTu();
                if (hhvt.ShowDialog() == DialogResult.OK)
                {
                    ChiTietVatTuHangHoa ctvthh = new ChiTietVatTuHangHoa();
                    addChild(ctvthh);
                }

            }
            if (Flag_PB.Flag == 4)
            {
                Flag_PB.ThemSua = 2;
                NhanVien nv = new NhanVien();
                if (nv.ShowDialog() == DialogResult.OK)
                {
                    ChiTietNhanVien ctnv = new ChiTietNhanVien();
                    addChild(ctnv);
                }

            }
            if (Flag_PB.Flag == 6)
            {
                Flag_PB.ThemSua = 2;
                DonVi dv = new DonVi();
                if (dv.ShowDialog() == DialogResult.OK)
                {
                    ChiTietDonVi ctdv = new ChiTietDonVi();
                    addChild(ctdv);
                }

            }
            if (Flag_PB.Flag == 8)
            {
                Flag_PB.ThemSua = 2;
                NhomKhachHangNCC nhomkhncc = new NhomKhachHangNCC();
                if (nhomkhncc.ShowDialog() == DialogResult.OK)
                {
                    ChiTietNhomKH_NCC ctnhom = new ChiTietNhomKH_NCC();
                    addChild(ctnhom);
                }

            }
        }

        private void barButtonItem34_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Flag_PB.Flag == 1)
            {
                if (MessageBox.Show("Bạn có thực sự muốn xóa Nhóm vật tư <" + NhomVatTu_PB.MaNhomVatTu + "> đã chọn không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    nvt_bus.XoaNhomVatTu(nvt_pb);
                    ChiTietNhomVatTuHangHoa ctnvt = new ChiTietNhomVatTuHangHoa();
                    addChild(ctnvt);
                }
            }
            if (Flag_PB.Flag == 2)
            {
                if (MessageBox.Show("Bạn có thực sự muốn xóa Kho <" +Kho_PB.MaKho + "> đã chọn không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    k_bus.XoaKho(k_pb);
                    ChiTietKho ctk = new ChiTietKho();
                    addChild(ctk);
                }
            }
            if (Flag_PB.Flag == 3)
            {
                if (MessageBox.Show("Bạn có thực sự muốn xóa Vật tư, Hàng hóa <" + VatTu_PB.MaVatTu + "> đã chọn không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    vattu_bus.XoaVatTu(vattu_pb);
                    ChiTietVatTuHangHoa ctvthh = new ChiTietVatTuHangHoa();
                    addChild(ctvthh);
                }
            }
            if (Flag_PB.Flag == 4)
            {
                if (MessageBox.Show("Bạn có thực sự muốn xóa Nhân viên <" + NhanVien_PB.MaNhanVien + "> đã chọn không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    nhanvien_bus.XoaNhanVien(nhanvien_pb);
                    ChiTietNhanVien ctnv = new ChiTietNhanVien();
                    addChild(ctnv);
                }
            }
            if (Flag_PB.Flag == 6)
            {
                if (MessageBox.Show("Bạn có thực sự muốn xóa Đơn vị <" + DonVi_PB.MaDonVi + "> đã chọn không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    dv_bus.XoaDonVi(dv_pb);
                    ChiTietDonVi ctdv = new ChiTietDonVi();
                    addChild(ctdv);
                }
            }
            if (Flag_PB.Flag == 8)
            {
                if (MessageBox.Show("Bạn có thực sự muốn xóa Nhóm khách hàng, nhà cung cấp <" + NhomKHNCC_PB.MaNhom + "> đã chọn không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    nhom_bus.XoaNhomKHNCC(nhom_pb);
                    ChiTietNhomKH_NCC nhom = new ChiTietNhomKH_NCC();
                    addChild(nhom);
                }
            }
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietKho ctk = new ChiTietKho();
            addChild(ctk);
        }

        private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            ChiTietNhapKho nk = new ChiTietNhapKho();
            addChild(nk);
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietVatTuHangHoa ctvt = new ChiTietVatTuHangHoa();
            addChild(ctvt);
        }

        private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietNhanVien ctnv = new ChiTietNhanVien();
            addChild(ctnv);
        }

        private void barButtonItem35_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietDonVi ctdv = new ChiTietDonVi();
            addChild(ctdv);
        }

        private void barButtonItem36_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietNhomKH_NCC ctkhncc = new ChiTietNhomKH_NCC();
            addChild(ctkhncc);
        }

        private void barButtonItem7_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietKhachHang ctkh = new ChiTietKhachHang();
            addChild(ctkh);
        }

        private void barbtnNhaCungCap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ChiTietNhaCungCap ctncc = new ChiTietNhaCungCap();
            addChild(ctncc);
        }

    }
}
